
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 2
 * @Author : WangRuoyu 
 * @Date : 2023/5/13 9:11
 */

#include "iostream"
#include "cstring"
#include "algorithm"

using namespace std;

const int m = 15;
const int n = 10;
const int h = 4;
int hh;
int k;
int screen[m][n];
int g[h][h];

bool check(int x, int y) {
    for (int i = 0; i < hh; ++i) {
        for (int j = 0; j < h; ++j) {
            if (screen[x + i][y + j] && g[i][j]) {
                return false;
            }
        }
    }
    return true;
}

int find() {
    for (int i = h - 1; i >= 0; --i) {
        for (int j = 0; j < h; ++j) {
            if (g[i][j]) {
                return i;
            }
        }
    }
}

int main() {

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> screen[i][j];
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < h; ++j) {
            cin >> g[i][j];
        }
    }
    cin >> k;

    hh = find() + 1;
    int lo = 0;
    for (; lo < m - hh + 1; ++lo) {
        if (!check(lo, k - 1)) {
            break;
        }
    }

    for (int i = 0; i < hh; ++i) {
        for (int j = 0; j < h; ++j) {
            if (g[i][j]) {
                screen[lo - 1 + i][k - 1 + j] = 1;
            }
        }
    }

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            cout << screen[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}